package com.itheima.service.impl;
import com.itheima.dao.AccountDao;
import com.itheima.pojo.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;


import javax.sql.DataSource;

@Service
public class AccountServiceImpl implements AccountService {
    //数据装配
   @Autowired
    AccountDao accountDao;
    @Autowired
    DataSource dataSource;
    @Override
    public void transfer(String froName, String toName, double money) {
        //获取账户信息
        Account accountDaoForName = accountDao.findByName(froName);
        Account accountDaoToName = accountDao.findByName(toName);
        //开始转账业务
        accountDaoForName.setMoney(accountDaoForName.getMoney()-money);
        accountDaoToName.setMoney(accountDaoToName.getMoney()+money);
        accountDao.update(accountDaoForName);
        //System.out.println(1/0);
        accountDao.update(accountDaoToName);

    }
    }
